<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" >
      <el-form-item label="名称" >
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入工号或姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属学院" >
       <treeselect :default-expand-level="1"  v-model="queryParams.deptId" :options="deptOptions" size="small" placeholder="请选择学院"  :show-count="true" style="width:300px;"/>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="blackPersonnelList" >
      <el-table-column label="编号" align="center" prop="id" width="60"/>
      <el-table-column label="机构"  prop="deptName":show-overflow-tooltip="true" />
      <el-table-column label="工号" align="center" prop="userName" width="80"/>
      <el-table-column label="姓名" align="center" prop="nickName" width="80"/>
      <el-table-column label="违规次数" align="center" prop="violateNum" width="80"/>
      <el-table-column label="状态" align="center" prop="removeByNo" width="60">
        <template slot-scope="scope">
            <span v-if="scope.row.isRemove==1">放生</span>
            <span v-else>禁闭</span>
          </template>
        </el-table-column>
      <el-table-column label="违规地点" align="center" prop="classRoom" :show-overflow-tooltip="true"/>
      <el-table-column label="实验项目" align="center" prop="experimentalProject" :show-overflow-tooltip="true"/>
      <el-table-column label="违反规定" align="center" prop="violationInfo" :show-overflow-tooltip="true"/>
      <el-table-column label="违反时间" align="center" prop="violationTime" width="100"/>
      <el-table-column label="操作" align="center" width="60">
        <template slot-scope="scope">
          <el-button
           v-if="scope.row.isRemove!=1"
            size="mini"
            type="text"
            icon="el-icon-s-check"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['labdata:blackPersonnel:edit']"
          >移除</el-button>
          <el-button
          v-if="scope.row.isRemove==1"
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

      <!-- 设置实验室黑名单对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
          <el-form ref="form" :model="form"  label-width="100px" >
            <el-row>
              <el-col :span="12" >
              <el-form-item label="姓名"  class="form_item_bottom">
                    <span>{{form.nickName}}/{{form.userName}}</span>
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="所属学院" class="form_item_bottom">
                {{form.deptName}}
              </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12" >
              <el-form-item label="违规地点"  class="form_item_bottom">
                    <span>{{form.classRoom}}</span>
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="违规次数" class="form_item_bottom">
                {{form.violateNum}}
              </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
              <el-form-item label="实验项目" class="form_item_bottom">
                <span>{{form.experimentalProject}}</span>
              </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
              <el-form-item label="违反规定" class="form_item_bottom">
                {{form.violationInfo}}
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="违规时间" class="form_item_bottom">
                {{form.violationTime}}
              </el-form-item>
              </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                <el-form-item label="判定老师" class="form_item_bottom">
                  <span>{{form.judgeTeacher}}</span>
                </el-form-item>
                </el-col>
              </el-row>
              <el-row>
              <el-row>
              <el-col :span="24">
              <el-form-item label="现场图片" class="form_item_bottom">
                <UploadCom ref="handUpload" disabled isImage :userFileList="fileList" />
              </el-form-item>
              </el-col>
              </el-row>
              <el-col :span="24">
              <el-form-item label="备注说明" class="form_item_bottom">
                {{form.comments}}
              </el-form-item>
              </el-col>
              </el-row>
           </el-form>
           <RemoveBlack ref="removeBack" @operation="handleOperation" :id="form.id"/>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary"  @click="submitForm" v-if="form.isRemove!=1" 
          v-hasPermi="['labdata:blackPersonnel:edit']">提 交</el-button>
          <el-button @click="cancel">关 闭</el-button>
        </div>
    </el-dialog>
  </div>
</template>

<script>
import {listBlackUsers, getBlackUserInfo} from "@/api/labdata/blacklist";
import UploadCom from "@/views/labdata/commons/upload.vue";
import RemoveBlack from "./remove_info.vue"
import { treeselect,getTreeLabel } from "@/api/labdata/orgnization";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "BlackPersonnel",
  components:{Treeselect,UploadCom,RemoveBlack},
  data() {
    return {
      // 遮罩层
      loading: true,
     // 部门树选项
     deptOptions: [],
      // 总条数
      total: 0,
      // 实验室黑名单人员表格数据
      blackPersonnelList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
     //附件集合
     fileList: [],
     // 查询参数
     queryParams: {
       pageNum: 1,
       pageSize: 10,
       userName: null,
     },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getTreeselect();
    this.getList();
  },
  methods: {
    /** 查询部门下拉树结构 */
    getTreeselect() {
       treeselect().then(response => {
         this.deptOptions = response.data;
       });
    },
    /** 查询实验室黑名单人员列表 */
    getList() {
      this.loading = true;
      listBlackUsers(this.queryParams).then(response => {
        this.blackPersonnelList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.fileList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBlackUserInfo(id).then(response => {
        this.form = response.data;
        this.fileList = this.form.images;
        this.open = true;
        this.title = "实验室黑名单人员移除";
      });
    },
    handleView(row){
        this.reset();
        const id = row.id || this.ids
        getBlackUserInfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "实验室黑名单移除信息";
        });
    },
    submitForm(){
      this.$refs["removeBack"].handSubmitForm();
    },
    handleOperation(){
      this.getList();
      this.open = false;
    },
  }
};
</script>
<style scoped lang="scss">
  .form_item_bottom{
    margin-bottom: 5px;
  }
</style>
